﻿/********************************************************************************
** 作者： 吴汉阳
** 创建时间： 2009-9-27
** 描述：
** 绑定资源树-涉及到的相关方法
********************************************************************************/
var UserID="";

Ext.InfoLoader = Ext.extend(Ext.tree.TreeLoader,
         { 
            tempvalue : null,
            createNode : function(attr){
            // apply baseAttrs, nice idea Corey!
	        if(this.tempvalue != null && this.tempvalue != ""){
	            var tempArray = this.tempvalue.split(",");
	            Ext.each(tempArray,function(n){
		            if(attr["id"] == n) {
		            
			            attr["checked"] = true;
		            }
	            },this);
	        }
                if(this.baseAttrs){
                    Ext.applyIf(attr, this.baseAttrs);
                }
                if(this.applyLoader !== false){
                    attr.loader = this;
                }
                if(typeof attr.uiProvider == 'string'){
                   attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
                }
                if(attr.nodeType){
                    return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
                }else{
                    return attr.leaf ?
                                new Ext.tree.TreeNode(attr) :
                                new Ext.tree.AsyncTreeNode(attr);
                }
            }
    });


    function ShowOrganUserWin(BindValue,RoleID,strTitle)
     {
         /*
         var rootNodeTrade =  new Ext.tree.AsyncTreeNode({
             id   : '-1',
             text : '所有菜单'
         }); 
         */
         var rootNodeTrade={nodeType: 'async',text:'所有用户',draggable:false,id:'TreeUserAll',collapsed:false,expanded:true};
         // 定义树对象
         var TradeTree = new Ext.tree.TreePanel(
         {
              columnWidth:1,
              id : 'treeUserTrade',
              margins : '2 2 0 2',
              autoScroll : true,
              root : rootNodeTrade,
              height : 209,
              width : 203,
              singleExpand : false,
              checkModel :"childCascade",  // 对树的级联多选
              onlyLeafCheckable : false,   // 对树所有结点都可选
              loader : new Ext.InfoLoader(
              {
                  dataUrl: strPath + 'SystemManage/GetOrganUserTree.aspx',
                 tempvalue: BindValue,
                 baseAttrs :
                 {
                    uiProvider : Ext.ux.TreeCheckNodeUI
                 }
             }), listeners: {
                 'load': loadHandler
             }
             
         }
        );

         winHbDepartMent = new Ext.Window({
             title: '&nbsp;' + strTitle,
             width: 420,
             height: 450,
             layout: 'fit',
             id: 'winHbOrgDepartMent',
             plain: true,
             closeAction: 'close',
             modal: true,
             deferredRender: false,
             bodyStyle: 'padding:5px;',
             buttonAlign: 'center',
             items: TradeTree,
             buttons: [{
                 text: '确定',
                 id: 'btnTreeUserInfo',
                 name: 'btnTreeUserInfo',
                 handler: function() {
                     var checkText = new Array;
                     var checkId = new Array;
                     var len = TradeTree.getChecked();
                     for (var i = 0; i < len.length; i++) {
                         if (len[i].id.indexOf('Org')!=-1) continue;
                         checkId.push(len[i].id);
                     }
                     UserID = checkId.toString();
                     UpdateUserRole(RoleID, UserID);
                     winHbDepartMent.close();
                 }
             }, {
                 text: '关闭',
                 handler: function() {
                     winHbDepartMent.close();
                 }
}]
             });
             winHbDepartMent.show();
             var myMask = new Ext.LoadMask('winHbOrgDepartMent', {
                 msg: "正在加载数据...",
                 removeMask: true
             });
             myMask.show();
             TradeTree.expandAll();

             function loadHandler(Node) { // 加载后事件响应处理
                 if (Node.isLast() && Node.getDepth() == '1')
                     myMask.hide();
             }
  }